/**
  * This file is part of Medusa.
  *
  * Authors: Uriel Fanelli <uriel.fanelli@gmail.com>
  *          Perthect <perthect@gmail.com>
  *          Marco Bizzarri <Marco.Bizzarri@gmail.com>
  *
  *
  * Medusa is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.

  * Medusa is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.

  * You should have received a copy of the GNU General Public License
  * along with Medusa; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */

#include <QUrl>

#include "singletab.h"

singleTab::singleTab(QNetworkAccessManager *manager)
{
    mainLayout = new QGridLayout;
    midLayout = new QVBoxLayout;

    this->manager = manager;
    this->view = new QWebView(this);
    this->progressBar = new GProgressBar;
    this->page = new QWebPage();
    this->view->setPage(this->page);
    this->page->setNetworkAccessManager(this->manager);

    midLayout->addWidget(view);
    midLayout->addWidget(progressBar);
    mainLayout->addLayout(midLayout, 0, 0);
    this->setLayout(mainLayout);

    connect(this->page, SIGNAL(linkClicked(QUrl)),  this->progressBar, SLOT(pageLoadStarted()));
    connect(this->view, SIGNAL(loadStarted()), this->progressBar, SLOT(pageLoadStarted()));
    connect(this->view, SIGNAL(loadStarted()), this, SLOT(pageLoadStarted()));
    connect(this->view, SIGNAL(loadProgress(int)), this->progressBar, SLOT(pageLoadInProgress(int)));
    connect(this->view, SIGNAL(loadFinished(bool)), this->progressBar, SLOT(pageLoadFinished(bool)));
    connect(this->view, SIGNAL(loadFinished(bool)), this, SLOT(pageLoadFinished(bool)));
}

void singleTab::mostrapagina(QUrl url)
{
    this->iomichiamo(url);
    this->view->load(url);
    this->view->show();
}

void singleTab::iomichiamo(QUrl url)
{
    michiamo = url;
}
QUrl singleTab::cometichiami()
{
    return michiamo;
}

/*
void singleTab::reload()
{
    //this->view->reload();
}
*/

singleTab::~singleTab()
{
    delete this->view;
    delete this->page;
}

void singleTab::pageLoadStarted()
{
    this->progressBar->show();
}

void singleTab::pageLoadFinished(bool result)
{
    this->progressBar->hide();
}
